/*******************************************************************************
 * Copyright (c) 2023, 2025 Lablicate GmbH.
 *
 * This program and the accompanying materials are made
 * available under the terms of the Eclipse Public License 2.0
 * which is available at https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 * 
 * Contributors:
 * Philip Wenig - initial API and implementation
 *******************************************************************************/
package org.eclipse.chemclipse.xxd.converter.supplier.ocx.internal.io;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import org.eclipse.chemclipse.xxd.converter.supplier.ocx.settings.Format;

public abstract class AbstractIO_1502 {

	public static final String VERSION = Format.CHROMATOGRAM_VERSION_1502;

	protected String readString(DataInputStream dataInputStream) throws IOException {

		int length = dataInputStream.readInt();
		StringBuilder builder = new StringBuilder();
		for(int i = 1; i <= length; i++) {
			builder.append(String.valueOf(dataInputStream.readChar()));
		}
		return builder.toString();
	}

	protected void writeString(DataOutputStream dataOutputStream, String value) throws IOException {

		if(value == null) {
			dataOutputStream.writeInt(-1);
		} else {
			dataOutputStream.writeInt(value.length());
			dataOutputStream.writeChars(value);
		}
	}
}
